package singlelist;

public class Test {

    //合并两个有序链表
    public static MySingleList.ListNode Merge (MySingleList.ListNode pHead1, MySingleList.ListNode pHead2) {
        // write code here
        MySingleList.ListNode newHead = new MySingleList.ListNode(1);
        MySingleList.ListNode cur = newHead;
        while(pHead1 != null && pHead2 != null){
            if(pHead1.val <= pHead2.val){
                cur.next = pHead1;
                pHead1 = pHead1.next;
            }else{
                cur.next = pHead2;
                pHead2 = pHead2.next;
            }
            cur = cur.next;
        }

        if(pHead1 != null){
            cur.next = pHead1;
        }else{
            cur.next = pHead2;
        }

        return newHead.next;
    }

    public static void main(String[] args) {

        MySingleList mySingleList = new MySingleList();

//        mySingleList.createList();

//        System.out.println("123213");

//        System.out.println(mySingleList.size());

//        System.out.println(mySingleList.contains(34));

        mySingleList.addLast(23);
        mySingleList.addLast(23);
        mySingleList.addLast(34);
        mySingleList.addLast(45);
        mySingleList.addLast(56);
        mySingleList.addLast(67);
        mySingleList.display();

        mySingleList.addLast(78);
        mySingleList.display();

        mySingleList.addIndex(0,23);
        mySingleList.display();

        mySingleList.addIndex(8,23);
        mySingleList.display();

        mySingleList.addIndex(4,23);
        mySingleList.display();

        mySingleList.addIndex(9,23);
        mySingleList.display();

        mySingleList.removeAllKey(23);
        mySingleList.display();


        MySingleList mySingleList1 = new MySingleList();
        mySingleList1.addLast(13);
        mySingleList1.addLast(23);
        mySingleList1.addLast(33);
        mySingleList1.addLast(42);
        mySingleList1.addLast(54);
        mySingleList1.addLast(74);
        mySingleList1.addLast(113);

        MySingleList mySingleList2 = new MySingleList();

        mySingleList2.head = Merge(mySingleList.head, mySingleList1.head);

        mySingleList2.display();

    }
}
